<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	//刷新阅读次数
	pdo_update('core_account_article',array('re_readnum +='=>1),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
	//获取文章数据
	$article_id=intval($_RQ['id']);
	$return['onlycontent']=intval($_RQ['onlycontent']);
	$return['item']=pdo_get('core_account_article',array('id'=>$article_id,'uniacid'=>$_SESSION['uniacid']));
	if(!$return['item']){
		exi('指定文章不存在！','error','list');
	}
	if(!$_SESSION['uid'] && $_SESSION['container']=='wechat' && $_SESSION['openid']){
		$return['ischecklogin']=cfc('core')->checklogin('','',true);
	}
	//分享积分
	if($_RQ['fromuser'] && $_RQ['fromuser']!=$_SESSION['uid']){
		model('core/article')->up_yingxiao($return['item'],$_RQ['fromuser']);
	}
	$article_rule_userd_money=pdo_getsum('core_credit_log',array('uniacid'=>$_SESSION['uniacid'],'type'=>2,'plugin'=>'core','tag'=>'article_'.$return['item']['id']),'fee');
	$return['item']['article_rule_userd_money']=$article_rule_userd_money>$return['item']['article_rule_userd_money']?$article_rule_userd_money:$article_rule_userd_money;
	//是否付费
	if($return['item']['fee']>0){
		$order=pdo_get('core_account_article_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'article_id'=>$return['item']['id']));
		if($order['ispay']==1){
			$return['item']['noread']=false;
		}else{
			$return['item']['noread']=true;
		}
		if($order['id']){
			$return['order_id']=$order['id'];
		}
	}
	$return['group_id']=$return['item']['fenlei'];
	$return['item']['readnum'] = $return['item']['readnum']+$return['item']['re_readnum'];
	unset($return['item']['re_readnum']);
	//点赞数=虚拟点赞数+真实点赞数
	$return['item']['likenum']+=pdo_count('core_account_article_like',array('article_id'=>$article_id,'like'=>1));
	//unset($return['item']['re_likenum']);
	$return['item']['advs']=json_decode($return['item']['advs'],true);
	$return['item']['createtime']=date('20y-m-d',$return['item']['createtime']);
	$return['fenlei']=pdo_getall('core_account_article_fenlei',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['item']['fenleiurl']=custom_url('jy_ad/news//id='.$return['item']['fenlei'],true);
	$return['item']['fenlei']=$return['fenlei'][$return['item']['fenlei']]['title'];
	$advs=array();
	if($return['item']['yingxiao']==1){
		$advs[]=$return['item']['advs'][0];
	}elseif($return['item']['yingxiao']==2){
		$num=count($return['item']['advs']);
		$return['index']=mt_rand(0,$num-1);
		$advs[]=$return['item']['advs'][$return['index']];
	}else{
		$advs=$return['item']['advs'];
	}
	$return['item']['advs']=$advs;
	//去掉多余空样式
	$return['item']['content']=str_replace('style=""','',$return['item']['content']);
	//$return['item']['content'] = str_replace('&nbsp;','',$return['item']['content']);
	$content=strip_tags($return['item']['content']);
	$return['item']['desc'] = $return['item']['desc'] ? $return['item']['desc'] : cfc('tools')->substr($content,0,36);
	$sharelink='jy_ad/news/detail/fromuser='.$_SESSION['uid'].'&id='.$return['item']['id'];
	$return['sharedata']=array(
			'title'=>$return['item']['title'] . '-' . $_SESSION['account']['title'],
			'desc'=>$return['item']['desc'],
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>$return['item']['pic_url']?tomedia($return['item']['pic_url']):tomedia($return['account']['logo']),
	);
	//检查当前用户是否点赞
	if($_SESSION['uid']){
		$return['like']=pdo_get('core_account_article_like',array('article_id'=>$article_id,'mid'=>$_SESSION['uid']),array('id','like'));
	}
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$fenleiid=intval($_RQ['group_id']);
	if($fenleiid){
		$params['fenlei']=$fenleiid;
	}
	$fields=array('id','title','fenlei','keyword','createtime','readnum','re_readnum','likenum','status','desc','pic_url','yingxiao');
	$orderby=array();
	$_RQ['page'] = $_RQ['page'] ? $_RQ['page'] : 1;
	$pindex = max(1, intval($_RQ['page']));
	if(intval($_RQ['num'])){
		$psize = intval($_RQ['num']);
	}else{
		$psize = 10;
	}
	$total='';
	$list=pdo_getslice('core_account_article',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['desc2'] = strip_tags(str_replace('&nbsp;','',$item['desc2']));
			$item['desc'] = $item['desc'] ? $item['desc'] : cfc('tools')->substr($item['desc2'],0,36);
			$item['picurl'] = $item['pic_url'] ? $item['pic_url'] : '../core/resource/images/nopic.jpg';
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['fenlei']=$fenlei[$item['fenlei']]['title'];
			$item['edit']=array('op'=>'edit','action'=>'article.list','query'=>'id='.$item['id']);
			$item['url']=custom_url('jy_ad/news/detail/id='.$item['id'],true);
		}
	}
	$hotlist=$list;
	paixu($hotlist,'re_readnum','desc');
	$return['list']=$list?$list:array();
	$return['os']=$_SESSION['os'];
	$return['post']=array('aid'=>$return['item']['id']);
	$return['xieyi']=$this->plugin_setting('xieyi');
	set_html('title',$return['item']['title']);
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['check']){
		exi('请先阅读《个人信息授权与隐私政策》！','error');
	}
	if(!$postdata['username'] || !$postdata['userphone']){
		exi('请填写姓名和电话！','error');
	}
	$data=array(
		'username'=>$postdata['username'],
		'userphone'=>$postdata['userphone'],
		'content'=>'咨询项目详情！',
		'title'=>'落地页咨询',
		'plugin_name'=>'jy_adtext',
	);
	$data['uniacid']=$_SESSION['uniacid'];
	$data['uid']=$_SESSION['uid'];
	$data['createtime']=TIMESTAMP;
	$data['type']=1;
	$data['aid']=$postdata['aid'];
	pdo_insert('core_account_message',$data);
	exi('提交成功');
}
?>